package com.groupname.dangerousdelves;

import java.util.ArrayList;

/**
 *  This class holds and manages the actual tiles that make up a dungeon.
 *
 *  @author Chris Fieldman (chrisf90)
 *  @version 2012.11.03
 */
public class Dungeon
{
    //~-------------------------------------------------------------------------
    // Member Variables
    private int width;
    private int height;

    private IActor[][] cells;

    private ArrayList<Room> rooms;

    private DungeonListener listener;

    //~-------------------------------------------------------------------------
    // Constructors
    /**
     * Create a new Dungeon object.
     * @param newWidth The width of this dungeon
     * @param newHeight The height of this dungeon
     */
    public Dungeon(int newWidth, int newHeight)
    {
        this.width = newWidth;
        this.height = newHeight;

        this.cells = new IActor[this.width][this.height];

        for (int x = 0; x < this.width; x++)
        {
            for (int y = 0; y < this.height; y++)
            {
                this.cells[x][y] = new Floor();
            }
        }

        this.rooms = new ArrayList<Room>();

        this.listener = new DungeonListener(this);
        EventManager.addListener(EventType.OpenDoor, this.listener);
    }

    //~-------------------------------------------------------------------------
    // Methods
    // ----------------------------------------------------------
    /**
     * Returns the room at the specified index.
     * @param index The index of the room
     * @return The room
     */
    public Room getRoom(int index)
    {
        return this.rooms.get(index);
    }
}